<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript数组</title>
</head>

<body>
    <script>
        //创建名为 cars0 的数组
        var cars0 = new Array();
        cars0[0] = "Saab";
        cars0[1] = "Volvo";
        cars0[2] = "BMW";
        //或者 (condensed array):
        var cars1 = new Array("Saab", "Volvo", "BMW");
        //或者 (literal array):
        var cars2 = ["Saab", "Volvo", "BMW"];
        //=============================================
        var i;
        var cars = new Array();
        cars[0] = "Saab";
        cars[1] = "Volvo";
        cars[2] = "BMW";

        for (i = 0; i < cars.length; i++) {
            document.write(cars[i] + "<br />");
        }
        //数组下标是基于零的，所以第一个项目是 [0]，第二个是 [1]，以此类推。
    </script>
</body>

</html>